/****************************************
Table 3, Table A.3
*****************************************/


clear all
set segmentsize 3g


* Load Data
use "$dir/Data/Final/MR_Census_linked_clean.dta", clear


/**************************************
Table 3
**************************************/


local outcomes_location farm urban ln_citypop lifetime_mig_husb lifetime_mig_wife 
local outcomes_econ_h ln_occscore_husb ln_inchat_husb prank_husb
local outcomes_marrage marrage_husb marrage_wife marrage_wife_pre18 marrage_wife_pre16 marrage_husb_pre20 marrage_husb_pre18 
local outcomes_family ncouples famsize nchlt5 multgen_high 
local outcomes_genetic deafblind_hmem

local FE cen_yr yob_h yob_w bpl_h bpl_w county_id 




foreach i in  location econ_h marrage family genetic  {
	eststo clear
foreach y in `outcomes_`i'' {
	eststo: reghdfe `y' isonymous ln_surname_count , absorb(`FE') vce(cluster couple_id)	
	qui summarize `y' if isonymous==0 & e(sample) == 1
	estadd scalar ymean = r(mean) 

	}

	esttab, nocons se keep(isonymous)

	esttab using "$dir/Output/TablesFigures/reg_`i'.tex", ///
		nobaselevels noomitted nocons se label replace keep(isonymous) ///
		title("`i' outcomes") stats(N ymean,  labels("N" "Mean of non-isonymous"))
	
	esttab using "$dir/Output/TablesFigures/reg_`i'.csv", ///
		nobaselevels noomitted nocons se label replace keep(isonymous) ///
		title("`i' outcomes") stats(N ymean,  labels("N" "Mean of non-isonymous"))


}

/**************************************
Table A.3
**************************************/

eststo clear

eststo: reghdfe ln_occscore_husb isonymous ln_surname_count , absorb(yob_h yob_w bpl_h bpl_w enumdistXyear) vce(cluster couple_id)	
eststo A1
 local obs7 = e(N)
sum  ln_occscore_husb if isonymous==0 & e(sample) == 1
local meanA = string(round(r(mean), .01))

eststo: reghdfe prank_husb isonymous ln_surname_count , absorb(yob_h yob_w bpl_h bpl_w enumdistXyear) vce(cluster couple_id)	
eststo A2
local obs8 = e(N)
sum  prank_husb if isonymous==0 & e(sample) == 1
local meanB = string(round(r(mean), .01))

eststo: reghdfe ln_inchat_husb isonymous ln_surname_count , absorb(yob_h yob_w bpl_h bpl_w enumdistXyear) vce(cluster couple_id)	
eststo A3
local obs9 = e(N)
sum  ln_inchat_husb if isonymous==0 & e(sample) == 1
local meanC = string(round(r(mean), .01))

 estout A1 A2 A3 using "$dir/Output/TablesFigures/resultsols_income_enumdist.tex", style(tex) replace ///
    keep(isonymous) ///
	cells(b(star fmt(%9.4f)) se(par)) ///
	nolabel collabels(none) mlabels(none) starlevels(* 0.10 ** 0.05 *** 0.01) ///
	varlabels(isoynmous "Isonymous Marriage")

local tex " \\ \hline"
local tex "`tex' Observations & `obs1' & `obs2' & & `obs3' \\"
local tex "`tex' Mean Dep. Var & `meanA' & `meanB' & `meanC'  \\"
local tex "`tex' \multicolumn{3}{p{8cm}}{\tiny \textit{}."
local tex "`tex' *** p<0.01, ** p<0.05, * p<0.1.} \\ \end{tabular} }"
	
esttab A1 A2 A3 using "$dir/Output/TablesFigures/results_ols_income_enumdista.tex", style(tex) replace booktabs ///
	d(*) nolabel collabels(none) noobs postfoot("`tex'") nonum ///
	mtitles("(1)" "(2)" "(3)") ///
	mgroups("Income (Log Occscore)" "Income Percentile-Rank" "Income (Log LIDO Score)", pattern(1 1 1) ///
	prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span}))
	
